<template>
  <div>
    <!-- 底部tabbar -->
    <div class="tab-bar">
      <view class="cu-bar tabbar margin-bottom-xl bg-white">

        <view v-for="item of tabBars"
          :key="item.id"
          class="action"
          :class="item.active?'text-green':'text-gray'"
          @tap="tabItem(item)">
          <button v-if="item.id==2" class="cu-btn icon-add bg-green shadow"></button>
          <view v-else :class="item.icon"></view> {{item.title}}
        </view>
        <!-- <view class="action text-gray add-action" @tap="tabItem(2)">
          <button class="cu-btn icon-add bg-green shadow"></button>
          发布
        </view> -->

      </view>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabBar',
  data () {
    return {
      tabBars: [
        { id: 0, title: '首页', path: '/pages/index/main', icon: 'icon-homefill', active: true },
        { id: 1, title: '分类', path: '/pages/del/main', icon: 'icon-similar', active: false },
        { id: 2, title: '发布', path: '/pages/form/main', icon: 'icon-add', active: false },
        { id: 3, title: '购物车', path: '/pages/bmi/main', icon: 'icon-cart', active: false },
        { id: 4, title: '我的', path: '/pages/demo/main', icon: 'icon-my', active: false },
      ]
    }
  },
  methods: {
    tabItem (item) {
      console.log(item)
      this.tabBars.forEach(ele => {
        ele.active = false
      });
      item.active = true
      wx.navigateTo({ url: item.path });
    }
  }
}
</script>

<style lang="scss" scoped>
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}
.margin-bottom-xl {
  margin-bottom: 0;
}
</style>
